<?php
if (!defined("LEVEL") || LEVEL < 30 || !defined("OK")) { header('location: ?home'); }

// biski kintamuju

    $host = "?id,46;a,8"; // pagrindinis
    $denny = "toolbar_reklama.php|conf.php|localhost.php|mg2_settings.php|sms_reklama.php|_config-rating.php|.svn|sms_config.php";
	$denny = explode("|", $denny);
    // knopkes
    $img_back="images/admin/back.gif";
    $img_folder="images/admin/folder.gif";
    $img_file="images/admin/file.gif";
    $img_home="images/admin/home.gif";
    $img_surce="images/icons/page_white_code_red.png";
	if (isset($url['d'])) { $d = urldecode($url['d']); } else { $d = './'; }


if (isset($url['v'])) {
	if (!in_array($url['v'], $denny) && is_file($d.$url['v'])) {
		$h = "<div style='width:100%;overflow:auto; height:300px;'><table bgcolor='#EEEEEE' width='100%'><tr><td width=30 valign='top'><code>";
		for ($i = 1; $i <= count(file($d.$url['v'])); $i++) $h .= $i.".<br>";
		$h .= "</code></td><td>";
		$h .= highlight_file($d.$url['v'], true);
		$h .= "</td></tr></table></div>";
		hide($url['v']." - failo turinys",$h);
		unset($h);
	}
	else { klaida("Draudziama!","Konfidenciali informacija!"); }
}

function s($arr, $str) {
   if (is_array($arr)) {
       $ilgis = strlen($str); $return = '';
       foreach ($arr as $key => $val) {
           $tmp = substr($val, 0, $ilgis);
           if ($str == $tmp) {
               $return .= $val."\n";
           }
       }
       return $return;
   }
   return false;
}



// grazina failo pletini
function strip_ext($name,$ext='') {
	$ext = substr($name, strlen($ext)-4, 4);
	if(strpos($ext,'.') === false) // jeigu tai folderis
	{
		return "    "; // grazinam biski tarpu kad rusiavimas butu ciki,
						  // susirusiuoja - folderiai virsuje
	}
	return $ext; // jei tai failas grazinam jo pletini
}


// Navigacija
$startdir = "./";
if(isset($d)) {
    $prev = $d;
    $folder = $d;   
} 
else { $folder = $startdir; $prev='';}
// END navigacija

$files = getFiles($folder);
$return = '';
foreach ($files as $file) {
    //if(strip_ext($file['name'])!='htaccess') {
    if($file['name']!='.htaccess' && $file['name'] != '.override') {	//Jeigu tai nera htaccess failas
        $image = $img_file;
        $extra = "<a href=\"".url('v,'.$file['name'].'')."\"><img src=\"$img_surce\" border=\"0\"/></a>";
        if($file['type']=='dir') {	//jeigu direktorija
            $image = $img_folder;
            $extra = "";
            $cmd='?id,46;a,8;d,'.urldecode($prev).$file['name'].'/';
        }
        else $cmd=$prev.$file['name'];
        //$return .= "$extra <a href=\"$cmd\" title=\"".$file['type'].", ".$file['sizetext']."\"><img src=\"$image\" border=\"0\" /> ".$file['name']."</a> <br/>";
        if ($file['type'] == 'file') { $return .= "$extra <a href=\"$cmd\" title=\"header=[".$file['name']."] body=[<br/><img src='".$cmd."'><br/>] fade=[on]\"><img src=\"$image\" border=\"0\" /> ".$file['name']."</a> <br/>"; }
        else { $return .= "$extra <a href=\"$cmd\" title=\"".$file['type'].", ".$file['sizetext']."\"><img src=\"$image\" border=\"0\" /> ".$file['name']."</a> <br/>"; }
    }
}
if (isset($d)) {
	$folder = explode("/",urldecode($d));
	$link = ''; $dir = '';
	foreach ($folder as $fname) {
		$dir .= $fname."/";
		$link .= " <a href='?id,46;a,8;d,".$dir."'>$fname</a>";
	}
}
lentele("Failų naršyklė: <a href=\"?id,46;a,8\">Failai</a>: ".((!empty($link))?$link:'')."", $return);

?>